home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Visual Database / Visual BASIC 5.0 (Ent. Edition) / Vb5ent Extractor.EXE / VB / SAMPLES / COMPTOOL / ADDINS / TABORDER / TABORDER.CLS < prev    next >
Encoding:
Visual Basic class definition  |  1996-11-23  |  7.4 KB  |  221 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "Connect"
  6. Attribute VB_GlobalNameSpace = False
  7. Attribute VB_Creatable = True
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = True
  10. Attribute VB_Description = "VB TabOrder Window"
  11. Option Explicit
  12.  
  13. Implements IDTExtensibility
  14.  
  15. Public WithEvents PrjHandler  As VBProjectsEvents          'projects event handler
  16. Attribute PrjHandler.VB_VarHelpID = -1
  17. Public WithEvents CmpHandler  As VBComponentsEvents        'components event handler
  18. Attribute CmpHandler.VB_VarHelpID = -1
  19. Public WithEvents CtlHandler  As VBControlsEvents          'controls event handler
  20. Attribute CtlHandler.VB_VarHelpID = -1
  21. Public WithEvents MenuHandler As CommandBarEvents          'command bar event handler
  22. Attribute MenuHandler.VB_VarHelpID = -1
  23. Dim mcbMenuCommandBar         As Office.CommandBarControl  'command bar object
  24.  
  25. Const guidMYTOOL$ = "{B7AFC8D0-EBE5-11cf-A497-00A0C911E8B0}"
  26.  
  27. Public NonModalApp As Boolean                              'used by AddIn Toolbar
  28. Attribute NonModalApp.VB_VarMemberFlags = "40"
  29.  
  30. Sub Show()
  31. Attribute Show.VB_MemberFlags = "40"
  32.   On Error GoTo ShowErr
  33.   
  34.   gwinWindow.Visible = True
  35.   gdocTabOrder.RefreshList 3
  36.   
  37.   Exit Sub
  38. ShowErr:
  39.   MsgBox Err.Description
  40. End Sub
  41.  
  42. Private Sub Class_Initialize()
  43.   NonModalApp = True   'used by addin toolbar
  44. End Sub
  45.  
  46. '------------------------------------------------------
  47. 'this method adds the Add-In to the VB Tools menu
  48. 'it is called by the VB addin manager
  49. '------------------------------------------------------
  50. Private Sub IDTExtensibility_OnConnection(ByVal VBInst As Object, ByVal ConnectMode As vbext_ConnectMode, ByVal AddInInst As VBIDE.AddIn, custom() As Variant)
  51.   On Error GoTo IDTExtensibility_OnConnectionErr
  52.   
  53.   Dim aiTmp As AddIn
  54.   
  55.   'save the vb instance
  56.   Set gVBInstance = VBInst
  57.  
  58.   If Not gwinWindow Is Nothing Then
  59.     'already running so just show it
  60.     Show
  61.     If ConnectMode = vbext_cm_AfterStartup Then
  62.       'started from the addin manager
  63.       AddToCommandBar
  64.     End If
  65.     Exit Sub
  66.   End If
  67.   
  68.   'create the tool window
  69.   If ConnectMode = vbext_cm_External Then
  70.     'need to see if it is already running
  71.     On Error Resume Next
  72.     Set aiTmp = gVBInstance.Addins("TabOrder.Connect")
  73.     On Error GoTo IDTExtensibility_OnConnectionErr
  74.     If aiTmp Is Nothing Then
  75.       'app is not in the VBADDIN.INI file so it is not in the collection
  76.       'so lets attempt to use the 1st addin in the collection just
  77.       'to get this app running and if there are none, an error
  78.       'will occur and this app will not run
  79.        Set gwinWindow = gVBInstance.Windows.CreateToolWindow(gVBInstance.Addins(1), "TabOrder.docTabOrder", LoadResString(10), guidMYTOOL$, gdocTabOrder)
  80.     Else
  81.       If aiTmp.Connect = False Then
  82.         Set gwinWindow = gVBInstance.Windows.CreateToolWindow(aiTmp, "TabOrder.docTabOrder", LoadResString(10), guidMYTOOL$, gdocTabOrder)
  83.       End If
  84.     End If
  85.   Else
  86.     'must've been called from addin mgr
  87.     Set gwinWindow = gVBInstance.Windows.CreateToolWindow(AddInInst, "TabOrder.docTabOrder", LoadResString(10), guidMYTOOL$, gdocTabOrder)
  88.   End If
  89.  
  90.   'sink the project, components and controls event handler
  91.   Set Me.PrjHandler = gVBInstance.Events.VBProjectsEvents
  92.   Set Me.CmpHandler = gVBInstance.Events.VBComponentsEvents(Nothing)
  93.   Set Me.CtlHandler = gVBInstance.Events.VBControlsEvents(Nothing, Nothing)
  94.   
  95.   If ConnectMode = vbext_cm_External Then
  96.     'started from the addin toolbar
  97.     Show
  98.   ElseIf ConnectMode = vbext_cm_AfterStartup Then
  99.     'started from the addin manager
  100.     AddToCommandBar
  101.   End If
  102.  
  103.   Exit Sub
  104.   
  105. IDTExtensibility_OnConnectionErr:
  106.   MsgBox Err.Description
  107.   
  108. End Sub
  109.  
  110. '------------------------------------------------------
  111. 'this event removes the commandbar menu
  112. 'it is called by the VB addin manager
  113. '------------------------------------------------------
  114. Private Sub IDTExtensibility_OnDisconnection(ByVal RemoveMode As vbext_DisconnectMode, custom() As Variant)
  115.   On Error GoTo IDTExtensibility_OnDisconnectionErr
  116.   'delete the command bar entry
  117.   mcbMenuCommandBar.Delete
  118.   
  119.   'save the form state for next time VB is loaded
  120.   If gwinWindow.Visible Then
  121.     SaveSetting APP_CATEGORY, App.Title, "DisplayOnConnect", "1"
  122.   Else
  123.     SaveSetting APP_CATEGORY, App.Title, "DisplayOnConnect", "0"
  124.   End If
  125.   
  126.   Set gwinWindow = Nothing
  127.   
  128. IDTExtensibility_OnDisconnectionErr:
  129.   
  130. End Sub
  131.  
  132. 'this event fires when the IDE is fully loaded
  133. Private Sub IDTExtensibility_OnStartupComplete(custom() As Variant)
  134.   AddToCommandBar
  135. End Sub
  136.  
  137. Private Sub IDTExtensibility_OnAddInsUpdate(custom() As Variant)
  138.   'comment needed to keep this stub code from
  139.   'being removed by VBA on compile
  140. End Sub
  141.  
  142. 'this event fires when the command bar control is clicked in the IDE
  143. Private Sub MenuHandler_Click(ByVal CommandBarControl As Object, handled As Boolean, CancelDefault As Boolean)
  144.   Show
  145. End Sub
  146.  
  147. 'this event fires when a control is added to the current form in the IDE
  148. Private Sub CtlHandler_ItemAdded(ByVal VBControl As VBIDE.VBControl)
  149.   If gwinWindow.Visible Then
  150.     gdocTabOrder.ControlAdded VBControl
  151.   End If
  152. End Sub
  153.  
  154. 'this event fires when a control is renamed on the current form in the IDE
  155. Private Sub CtlHandler_ItemRenamed(ByVal VBControl As VBIDE.VBControl, ByVal OldName As String, ByVal OldIndex As Long)
  156.   If gwinWindow.Visible Then
  157.     gdocTabOrder.ControlRenamed VBControl, OldName, OldIndex
  158.   End If
  159. End Sub
  160.  
  161. 'this event fires when a control is removed from the current form in the IDE
  162. Private Sub CtlHandler_ItemRemoved(ByVal VBControl As VBIDE.VBControl)
  163.   If gwinWindow.Visible Then
  164.     gdocTabOrder.ControlRemoved VBControl
  165.   End If
  166. End Sub
  167.  
  168. 'this event fires when a form becomes activated in the IDE
  169. Private Sub CmpHandler_ItemActivated(ByVal VBComponent As VBIDE.VBComponent)
  170.   On Error GoTo CmpHandler_ItemActivatedErr
  171.   If gwinWindow.Visible Then
  172.     gdocTabOrder.RefreshList 0
  173.   End If
  174. CmpHandler_ItemActivatedErr:
  175. End Sub
  176.  
  177. 'this event fires when a form is selected in the project window
  178. Private Sub CmpHandler_ItemSelected(ByVal VBComponent As VBIDE.VBComponent)
  179.   CmpHandler_ItemActivated VBComponent
  180. End Sub
  181.  
  182. Sub AddToCommandBar()
  183. Attribute AddToCommandBar.VB_MemberFlags = "40"
  184.   On Error GoTo AddToCommandBarErr
  185.   
  186.   'make sure the standard toolbar is visible
  187.   gVBInstance.CommandBars(2).Visible = True
  188.   
  189.   'add it to the command bar
  190.   'the following line will add the TabOrder manager to the
  191.   'Standard toolbar to the right of the ToolBox button
  192.   Set mcbMenuCommandBar = gVBInstance.CommandBars(2).Controls.Add(1, , , gVBInstance.CommandBars(2).Controls.Count)
  193.   'set the caption
  194.   mcbMenuCommandBar.Caption = LoadResString(200)
  195.   'copy the icon to the clipboard
  196.   Clipboard.SetData LoadResPicture(1000, 0)
  197.   'set the icon for the button
  198.   mcbMenuCommandBar.PasteFace
  199.   
  200.   'sink the event
  201.   Set Me.MenuHandler = gVBInstance.Events.CommandBarEvents(mcbMenuCommandBar)
  202.   
  203.   'restore the last state
  204.   If GetSetting(APP_CATEGORY, App.Title, "DisplayOnConnect", "0") = "1" Then
  205.     'set this to display the form on connect
  206.     Me.Show
  207.   End If
  208.   
  209.   Exit Sub
  210.     
  211. AddToCommandBarErr:
  212.   MsgBox Err.Description
  213. End Sub
  214.  
  215. Private Sub PrjHandler_ItemRemoved(ByVal VBProject As VBIDE.VBProject)
  216.   'this takes care of the user removing the only project
  217.   If gwinWindow.Visible Then
  218.     gdocTabOrder.RefreshList 0
  219.   End If
  220. End Sub
  221.